<?php

namespace App\Http\Controllers\Admin\V1;

use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\SettingRequest;
use App\Models\Setting;
use App\Transformers\Admin\SettingTransformer;
use Dingo\Api\Http\Response;
use Illuminate\Support\Facades\Redis;

class SettingController extends Controller
{
    /**
     * 基础设置列表
     *
     * @return Response
     */
    public function index()
    {
        $settings = Setting::all();

        return $this->response->collection($settings, new SettingTransformer());
    }

    /**
     * 基础摄设置详情
     *
     * @param Setting $setting
     * @return Response
     */
    public function show($setting)
    {
        $settingDatil = Setting::where('type', $setting)->firstOrfail();

        return $this->response->item($settingDatil, new SettingTransformer());
    }

    /**
     * 基础配置修改
     *
     * @param SettingRequest $request
     * @param Setting $setting
     * @return Response
     */
    public function update(SettingRequest $request, $setting)
    {
        Setting::where('type', $setting)->update($request->all());

        Redis::del($setting);

        return $this->response->noContent();
    }
}
